package com.qf.java2201.web;

import com.qf.java2201.dao.impl.OrderDaoImpl;
import com.qf.java2201.pojo.HUser;
import com.qf.java2201.service.OrderService;
import com.qf.java2201.service.impl.OrderServiceImpl;
import com.qf.java2201.utils.DateUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Date;

@WebServlet("/upYyzt")
public class UpdateYyztServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //要更改的单子的id
        String oid = req.getParameter("oid");
        //要把单子改为什么状态
        String zt = req.getParameter("zt");
        // type 是 预约单原本的状态
        // 1  未付款   想要取消未付款的单子
        // 2  未付款   想要付款
        // 3  已付款   想要取消已付款的单子
        // 4  已付款   想要完成已付款的单子
        String type = req.getParameter("type");

        //得到预约单的预约日期
        String odate = req.getParameter("odate");

        Date date = DateUtil.strToDate(odate, "yyyy-MM-dd");
        HttpSession session = req.getSession();
        HUser hUser = (HUser) session.getAttribute("u");

        Integer did = hUser.getUi().getDid();   //患者id
        OrderService orderService = new OrderServiceImpl();

       int result = orderService.updateOrserByType(oid, zt, type, did, date);
       if (result == 1) {
           //gaid成功
           resp.getWriter().println("1");
       }else {
           //更改失败
           resp.getWriter().println("0");
       }

    }
}
